package com.yonyou.pmclouds.procedure.processor;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.procedure.entity.ProcedureVO;
import com.yonyou.pmclouds.procedure.rmiimpl.ProcedureMaintainImpl;


public class ProcedureDeleteRefCheck implements SingleProcessor<ProcedureVO> {

    private ProcedureMaintainImpl maintain;

    public ProcedureDeleteRefCheck(ProcedureMaintainImpl maintain) {
        this.maintain = maintain;
    }

    @Override
    public void process(ProcedureVO vo, ProcedureVO orig) throws BusinessException {
        int status = maintain.getProcedureRefStatus(orig.getPkProcedure(), orig.getPkTenant());
        if (status == ProcedureMaintainImpl.STATUS_REF_BY_CHILD) {
            throw new BusinessException("当前工序已经存在下级工序，不可删除！");
        }
        if (status == ProcedureMaintainImpl.STATUS_REF_BY_QUALITY) {
            throw new BusinessException("当前工序已经被检查标准引用，不可删除！");

        }if (status==ProcedureMaintainImpl.STATUS_REF_BY_PROJECT){
            throw new BusinessException("当前工序已经被项目档案引用，不可删除！");
        }
        if (status != ProcedureMaintainImpl.STATUS_NOT_REF) {
            throw new BusinessException("当前工序已经被引用，不可删除！");
        }
    }
}
